
/**
 * Module dependencies.
 */

var express = require('express');
var routes = require('./routes');
var http = require('http');
var path = require('path'); 
var initDB = require('./sql/initDB.js'); 
var app = express();

// all environments
app.set('port', process.env.PORT ||80);
app.use(express.static('public'));
app.use(app.router);
var logger = require('./util/log.js');
initDB.init();



// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
//用户注册页面
app.get('/register', routes.register);
//用户同意页面
app.get('/agreement',routes.agreement);
//登录验证
app.post('/login',routes.login);
//验证用户名是否重复
app.post('/useridIsExist',routes.useridIsExist);
//注册新的用户
app.post('/addUser',routes.addUser);
//打开主页面
app.get('/main',routes.main);
//获取note数据
app.post('/getNote',routes.getNote);
//保存note数据
app.post('/saveNote',routes.saveNote);
//删除日记数据
app.post('/deleteNote',routes.deleteNote);
//打开个人信息修改页面
app.get('/personInformation',routes.personInformation);
// 获取个人信息
app.post('/getUserInfo',routes.getUserInfo);
//修改个人信息
app.post('/saveUserInfo',routes.saveUserInfo);


http.createServer(app).listen(app.get('port'), function(){
  logger.logger("normal").info('服务器已经启动，端口号：' + app.get('port'));
});
